package com.qf.agro.web.controller.device;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.qf.agro.common.sys.ResultInfo;
import com.qf.agro.pojo.device.SmartDeviceType;
import com.qf.agro.service.device.SmartDeviceTypeService;
import com.qf.agro.vo.OptionVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @company：千锋教育
 * @author：zhy
 * @date：2023/7/2
 */
@RestController
@RequestMapping("/device/type")
public class SmartDeviceTypeController {

    @Resource
    private SmartDeviceTypeService smartDeviceTypeService;

    /**
     * 分页查询智能设备分类
     * @param pageNum
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/page")
    public ResultInfo findPage(@RequestParam(defaultValue = "1",value = "page") Integer pageNum, @RequestParam(defaultValue = "5") Integer pageSize, String name){
        //1.调用业务层查询
        Page page = smartDeviceTypeService.findPage(pageNum, pageSize, name);
        //2.返回
        return ResultInfo.success(page);
    }

    /**
     * 保存智能设备分类
     * @param smartDeviceType
     * @return
     */
    @PostMapping
    public ResultInfo save(@RequestBody SmartDeviceType smartDeviceType){
        //1.调用业务层保存
        smartDeviceTypeService.save(smartDeviceType);
        //2.返回
        return ResultInfo.success(null);
    }

    /**
     * 更新智能设备分类
     * @param smartDeviceType
     * @return
     */
    @PutMapping
    public ResultInfo update(@RequestBody SmartDeviceType smartDeviceType){
        //1.调用业务层更新
        smartDeviceTypeService.update(smartDeviceType);
        //2.返回
        return ResultInfo.success(null);
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping
    public ResultInfo delete(Long id){
        //1.调用业务层删除
        smartDeviceTypeService.delete(id);
        //2.返回
        return ResultInfo.success(null);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping
    public ResultInfo findById(Long id){
        //1.调用业务层查询
        SmartDeviceType smartDeviceType = smartDeviceTypeService.findById(id);
        //2.返回
        return ResultInfo.success(smartDeviceType);
    }

    /**
     * 根据id查询
     * @param
     * @return
     */
    @GetMapping("/selectOptions")
    public ResultInfo selectOptions( ){
        //1.调用业务层查询
        List<OptionVo> optionVoList = smartDeviceTypeService.selectDeviceOptions();
        //2.返回
        return ResultInfo.success(optionVoList);
    }
}
